<template>
  <el-row>
    <div class="reply" v-for="(item,index) of comment.data" :key="index">
      <el-row class="user" v-if="item.account">
        <img :src="$axios.defaults.baseURL + item.account.defaultAvatar" alt />
        <el-col class="userInfo">
          {{item.account.nickname}}
          <span>{{$moment(item.created_at).format("YYYY-MM-DD hh:mm")}}</span>
        </el-col>
      </el-row>
      <postComments v-if="item.parent" :comment="item.parent" @parentCallReply="replyBtn"></postComments>
      <div class="replyBox">
        <el-row class="replyContent">
          {{item.content}}
          <div v-for="(item,index) of item.pics" :key="index" class="cmt-img">
            <img v-if="item.url" :src="$axios.defaults.baseURL + item.url" />
          </div>
        </el-row>
        <el-row class="replyBtn" type="flex" justify="end">
          <span @click="replyBtn(item.id,item.account.nickname)">回复</span>
        </el-row>
      </div>
    </div>
  </el-row>
</template>

<script>
import postComments from "./postComments";
export default {
  components: {
    postComments
  },
  props: ["comment"],
  methods: {
    replyBtn(id, nickname) {
      console.log("1", id, nickname);
      this.$emit("parentCallReply", id, nickname);
    }
  }
};
</script>

<style lang="less" scoped>
//回复的评论
.reply {
  border: 1px solid #0a0;
  border-radius: 10px;
  padding: 30px;
  margin-bottom: 10px;
  .user {
    display: flex;
    align-self: center;
    height: 20px;
    line-height: 20px;
    margin-bottom: 10px;
    img {
      width: 20px;
      border-radius: 10px;
      margin-right: 5px;
    }
    .userInfo {
      font-size: 14px;
      span {
        font-size: 12px;
        color: #999;
      }
    }
  }
  .contentReply {
    margin: 20px;
  }
  .replyBtn {
    font-size: 12px;
    color: #333;
  }
}
.replyContent {
  .cmt-img {
    width: 80px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
    margin-right: 5px;
    margin-top: 10px;
    padding: 5px;
    border: 1px dashed #ddd;
    img {
      width: 100%;
      height: 100%;
      object-fit: cover;
    }
  }
}
</style>